﻿namespace HySoft.Cash.DB
{
    using Huayou.Common.Database;
    using Huayou.Utils;
    using HySoft.Cash.BaseClass;
    using HySoft.Cash.Structure;
    using System;
    using System.Data;

    public class TuserinfoDB : BaseDB
    {
        public TuserinfoDB(DBOperate oper) : base(oper)
        {
        }

        public bool Add(TuserinfoDT detail)
        {
            int num = 0;
            string strSql = string.Concat(new object[] { "INSERT INTO tUserInfo (Username,Password,RuleSid,IsOpen) VALUES ('", StringUtils.ToSQL(detail.Username), "','", StringUtils.ToSQL(detail.Password), "',", detail.RuleSid, ",", detail.IsOpen, ")" });
            try
            {
                try
                {
                    num = base.ExecuteForInt(strSql);
                }
                catch (Exception exception)
                {
                    throw exception;
                }
            }
            finally
            {
            }
            return (num == 1);
        }

        public bool Delete(int Sid)
        {
            int num = 0;
            string strSql = "DELETE FROM tUserInfo where (Sid=" + Sid + ")";
            try
            {
                try
                {
                    num = base.ExecuteForInt(strSql);
                }
                catch (Exception exception)
                {
                    throw exception;
                }
            }
            finally
            {
            }
            return (num == 1);
        }

        public bool Edit(TuserinfoDT detail)
        {
            int num = 0;
            string strSql = string.Concat(new object[] { "UPDATE tUserInfo set Username='", StringUtils.ToSQL(detail.Username), "',Password='", StringUtils.ToSQL(detail.Password), "',RuleSid=", detail.RuleSid, ",IsOpen=", detail.IsOpen, " where (Sid=", detail.Sid, ")" });
            try
            {
                try
                {
                    num = base.ExecuteForInt(strSql);
                }
                catch (Exception exception)
                {
                    throw exception;
                }
            }
            finally
            {
            }
            return (num == 1);
        }

        public TuserinfoDT Get(int Sid)
        {
            TuserinfoDT odt = new TuserinfoDT();
            try
            {
                try
                {
                    string strSql = "select * from tUserInfo where (Sid=" + Sid + ")";
                    DataTable table = base.ExecuteForDataTable(strSql);
                    DataRow row = null;
                    if (table.Rows.Count >= 0)
                    {
                        row = table.Rows[0];
                        odt.Sid = Convert.ToInt32(row["Sid"]);
                        odt.Username = Convert.ToString(row["Username"]);
                        odt.Password = Convert.ToString(row["Password"]);
                        odt.RuleSid = Convert.ToInt32(row["RuleSid"]);
                        odt.PubDate = Convert.ToDateTime(row["PubDate"]);
                        odt.IsOpen = Convert.ToInt32(row["IsOpen"]);
                    }
                }
                catch (Exception exception)
                {
                    throw exception;
                }
            }
            finally
            {
            }
            return odt;
        }

        public DataTable GetList()
        {
            DataTable table = null;
            try
            {
                try
                {
                    string strSql = "select * from tUserInfo";
                    table = base.ExecuteForDataTable(strSql);
                }
                catch (Exception exception)
                {
                    throw exception;
                }
            }
            finally
            {
            }
            return table;
        }
    }
}

